package com.china08.yxyapi.service.manage.tec.teaching.lecture.impl;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.UUID;

import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.Assert;

import com.china08.yxyapi.api.manage.tec.teaching.lecture.pack.LectureCrtPackAndHomeworkController;
import com.china08.yxyapi.api.manage.tec.teaching.lecture.pack.LectureCrtPackAndHomeworkController.MyClass;
import com.china08.yxyapi.api.manage.tec.teaching.lecture.pack.LectureCrtPackAndHomeworkController.RequesRes;
import com.china08.yxyapi.api.manage.tec.teaching.lecture.pack.LectureCrtPackAndHomeworkController.StuModel;
import com.china08.yxyapi.entity.db.res.YxyResResource;
import com.china08.yxyapi.entity.db.yxy.YxyQuesKnow;
import com.china08.yxyapi.entity.es.ElasticYxyYxyQuesResource;
import com.china08.yxyapi.entity.mg.homework.HomeWorkQuesUsed;
import com.china08.yxyapi.entity.mg.homework.HomeworkTask;
import com.china08.yxyapi.entity.mg.homework.HomeworkTaskClass;
import com.china08.yxyapi.entity.mg.homework.HomeworkTaskQues;
import com.china08.yxyapi.entity.mg.homework.HomeworkTaskQues.Article;
import com.china08.yxyapi.entity.mg.homework.HomeworkTaskReport;
import com.china08.yxyapi.entity.mg.lecture.YxyLecturePrePack;
import com.china08.yxyapi.entity.mg.lecture.YxyLectureRes;
import com.china08.yxyapi.entity.mg.lecture.YxyLectureRes.Knows;
import com.china08.yxyapi.repository.db.YxyQuesKnowRepository;
import com.china08.yxyapi.repository.db.YxyResResourceRepository;
import com.china08.yxyapi.repository.mg.homework.HomeworkQuesUsedRepository;
import com.china08.yxyapi.repository.mg.homework.HomeworkTaskClassRepository;
import com.china08.yxyapi.repository.mg.homework.HomeworkTaskQuesRepository;
import com.china08.yxyapi.repository.mg.homework.HomeworkTaskReportRepository;
import com.china08.yxyapi.repository.mg.homework.HomeworkTaskRepository;
import com.china08.yxyapi.repository.mg.lecture.YxyLecturePrePackRepository;
import com.china08.yxyapi.repository.mg.lecture.YxyLectureResRepository;
import com.china08.yxyapi.service.manage.tec.teaching.homework.ElasticQuesService;
import com.china08.yxyapi.service.manage.tec.teaching.lecture.LectureCrtPackAndHomeworkService;
import com.china08.yxyapi.util.EsResourcePvUpdateUtil;

@Service
public class LectureCrtPackAndHomeworkServiceImpl implements LectureCrtPackAndHomeworkService {
    private final static Logger LOGGER = LoggerFactory.getLogger(LectureCrtPackAndHomeworkServiceImpl.class);

    @Autowired
    private HomeworkTaskRepository taskRepository;

    @Autowired
    private HomeworkTaskClassRepository taskClassRepository;

    @Autowired
    private HomeworkTaskQuesRepository taskQuesRepository;

    @Autowired
    private HomeworkTaskReportRepository taskReportRepository;

    @Autowired
    private ElasticQuesService elasticService;

    @Autowired
    private YxyQuesKnowRepository qKnowRepository;

    @Autowired
    private HomeworkQuesUsedRepository quesUsedRepository;

    @Autowired
    private YxyLecturePrePackRepository yxyLecturePrePackRepository;

    @Autowired
    private YxyLectureResRepository yxyLectureResRepository;

    @Autowired
    private YxyResResourceRepository yrrr;

    /**
     * 
     * // 备课包id String prePackId, </br>
     * 
     * // 发布作业需要前台将资源的用途传递过来,</br>
     * // 根据资源用途,进行作业的发布. List<RequesRes> requesRes,
     * 
     * // 预习作业开始时间 Date usesProviewBeginDate, </br>
     * // 预习作业结束时间 Date usesProviewEndDate, </br>
     * 
     * // 课后作业开始时间 Date usesHomeworkBeginDate, </br>
     * // 课后作业结束时间 Date usesHomeworkEndDate,</br>
     * 
     * 发布作业的班级 List<MyClass> myClass)
     */
    @Override
    public boolean createHomework(String prePackId, List<RequesRes> requesRes, String usesProviewBeginDate,
            String usesProviewEndDate, String usesHomeworkBeginDate, String usesHomeworkEndDate, List<MyClass> myClass,
            String schoolId, String schoolNick, String userId, String userNick, List<String> parentsIdnew,
            String domainName) {
        // TODO Richard.Wang 备课包,发布作业
        boolean flag = true;
        // 先循环 资源用途, "预习作业", "课后作业",需要发布作业系统</br>
        List<RequesRes> resHomework = new ArrayList<LectureCrtPackAndHomeworkController.RequesRes>();

        YxyLecturePrePack yxyLecturePrePack = yxyLecturePrePackRepository.findById(prePackId);

        // 题组单独发送试题,
        // 资源合并发布作业,
        // 每个班发布一次作业</br>
        if (requesRes != null && requesRes.size() > 0) {
            for (RequesRes res : requesRes) {
                EsResourcePvUpdateUtil.updateEsResoure(res.resId + "_2");
                YxyResResource resResource = yrrr.findById(res.resId);
                if (resResource != null) {
                    resResource.setDownloadCount(resResource.getDownloadCount() + 1l);
                    yrrr.save(resResource);
                }
                // 试题类型
                if (0 == res.courseType) {
                    // 预习作业
                    if (res.resUsed.indexOf(2) > 0) {
                        YxyLectureRes lres = yxyLectureResRepository.findByResourceId(res.resId);
                        sendQuesHomeWork(lres, 0, yxyLecturePrePack, usesProviewBeginDate, usesProviewEndDate, myClass,
                                res.resName, schoolId, schoolNick, userId, userNick, parentsIdnew);
                    }
                    // 课后作业
                    if (res.resUsed.indexOf(3) > 0) {
                        YxyLectureRes lres = yxyLectureResRepository.findByResourceId(res.resId);
                        String resName = res.resName;
                        sendQuesHomeWork(lres, 1, yxyLecturePrePack, usesHomeworkBeginDate, usesHomeworkEndDate,
                                myClass, resName, schoolId, schoolNick, userId, userNick, parentsIdnew);
                    }
                } else {// 资源类型
                    // 预习作业
                    if (res.resUsed.indexOf(2) > 0) {
                        resHomework.add(res);
                    }

                }

            }
            // 发布 资源作业为 文档类作业
            if (resHomework != null && resHomework.size() > 0) {
                sendNoticeHomeWork(resHomework, yxyLecturePrePack, usesProviewBeginDate, usesProviewEndDate, myClass,
                        yxyLecturePrePack.getPackName(), schoolId, schoolNick, userId, userNick, parentsIdnew,
                        domainName);
            }
        }

        return flag;
    }

    /**
     * 发布通知类作业
     * 
     * @param lectureType
     * @param yxyLecturePrePack
     * @param beginDate
     * @param doneDate
     * @param myClass
     * @param quesGoupName
     * @param schoolId
     * @param schoolName
     * @param userId
     * @param userNick
     * @throws ParseException
     */
    private void sendNoticeHomeWork(List<RequesRes> resHomework, YxyLecturePrePack yxyLecturePrePack, String beginDate,
            String doneDate, List<MyClass> myClass, String quesGoupName, String schoolId, String schoolName,
            String userId, String userNick, List<String> parentsIdnew, String domainName) {
        LOGGER.info("开始发布作业");

        // 开始时间
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS Z");

        Date startDate = null;
        Date endDate = null;
        try {
            startDate = sdf.parse(beginDate.replace("Z", " UTC"));
            endDate = sdf.parse(doneDate.replace("Z", " UTC"));
            Assert.isTrue(startDate.getTime() < endDate.getTime(), "截止时间不能小于开始时间");
        } catch (ParseException e) {
            e.printStackTrace();
        }
        //

        HomeworkTask task = new HomeworkTask();
        List<String> classIdList = new ArrayList<String>();
        for (MyClass classReqModel : myClass) {
            String classId = classReqModel.classId;
            classIdList.add(classId);
        }
        // 学段, 学科,学科名称
        String stage = yxyLecturePrePack.getPhaseId();
        String subject = yxyLecturePrePack.getSubjectId();
        String subjectName = yxyLecturePrePack.getSubjectName();
        //
        task.setTitle(quesGoupName);// 文档的名称
        task.setSubTitle(quesGoupName);// 文档的名称
        task.setSchoolId(schoolId);
        task.setPublishUserId(userId);
        task.setPublishUserNick(userNick);
        task.setStage(stage);
        task.setSubject(subject);
        task.setSubjectName(subjectName);
        task.setPublishAnswer(0);
        task.setSource(1);// 来源, 备授课
        task.setLectureType(0);// 备授课类型,文档只能为 "预习作业"
        task.setPublishDate(startDate);
        task.setClassIds(classIdList);
        task.setPredictDate(endDate);
        // task.setKnowIds(reqModel.knowIdList);
        // task.setKnowNames(reqModel.knowNameList);
        task.setTaskType("2");
        task.setIfNeedSumbit(false);
        task = taskRepository.save(task);
        // 极光推送
        LectureCrtPackAndHomeworkController.sendMessage(subjectName, schoolId, parentsIdnew, startDate);
        // 存储班级作业
        List<HomeworkTaskClass> taskClassList = new ArrayList<HomeworkTaskClass>();
        HomeworkTaskClass taskClass = null;
        for (MyClass classReqModel : myClass) {
            taskClass = new HomeworkTaskClass();
            taskClass.setTitle(task.getTitle());
            taskClass.setSubTitle(task.getSubTitle());
            taskClass.setClassId(classReqModel.classId);
            taskClass.setClassName(classReqModel.classNick);
            taskClass.setNumOfStudent(classReqModel.studentNum);
            taskClass.setGrade(classReqModel.grade);
            taskClass.setTaskId(task.getId());
            taskClass.setSchoolId(schoolId);
            taskClass.setStage(task.getStage());
            taskClass.setSubject(task.getSubject());
            taskClass.setSubjectName(task.getSubjectName());
            taskClass.setPublishDate(task.getPublishDate());
            taskClass.setPredictDate(task.getPredictDate());
            taskClass.setPublishUserId(task.getPublishUserId());
            taskClass.setPublishUserNick(task.getPublishUserNick());
            taskClass.setTaskType(task.getTaskType());
            taskClass.setSource(1);// 来源, 备授课
            taskClass.setLectureType(0);// 备授课类型,文档只能为 "预习作业"
            taskClass.setLectureId(classReqModel.packId);
            taskClassList.add(taskClass);
        }
        taskClassRepository.save(taskClassList);

        // 通知类作业
        List<HomeworkTaskQues> taskQuesList = new ArrayList<HomeworkTaskQues>();
        HomeworkTaskQues taskQues = new HomeworkTaskQues();
        taskQues.setTitle(task.getTitle());
        taskQues.setSubTitle(task.getSubTitle());
        taskQues.setTaskId(task.getId());
        taskQues.setPredictDate(task.getPredictDate());
        // 生成通知类试题id 2017-12-11 tz改成yd（梁岩）
        taskQues.setQuesId("yd" + UUID.randomUUID());
        // 通知类试题的文档
        List<Article> quesArticleList = new ArrayList<Article>();
        Article article = null;
        for (RequesRes articleReqModel : resHomework) {
            String url = "";
            if (domainName.contains("hrbeduy")) {
                url = "yxyres.hrbeduy.com/res/browse/";
            } else {
                url = "yxy.res.91yunxiao.com/res/browse/";
            }
            url = url + articleReqModel.resId;
            article = new Article();
            article.setArticle_name(articleReqModel.resName);
            article.setUrl(url);
            quesArticleList.add(article);
        }
        // 2017-12-11 2改成5（梁岩）
        taskQues.setQuesType("5");
        taskQues.setQuesArticle(quesArticleList);
        taskQues.setTeacherId(userId);
        taskQues.setStage(stage);
        taskQues.setSubject(subject);
        taskQues.setOrder(1);// 通知类试题序号
        taskQues.setTaskType(task.getTaskType());
        // 通知类作业是否需要在线提交
        taskQues.setIfNeedSumbit(false);
        taskQuesList.add(taskQues);
        taskQuesRepository.save(taskQuesList);

        // 存储学生作业
        // 设置每个学生的试题作业
        // 年度
        List<HomeworkTaskReport> taskReportList = new ArrayList<HomeworkTaskReport>();
        HomeworkTaskReport taskReport = null;
        LocalDate localDate = LocalDate.now();
        String annual = null;
        if (localDate.getMonthValue() < 9) {
            annual = (localDate.getYear() - 1) + "";
        } else {
            annual = localDate.getYear() + "";
        }
        for (MyClass classReqModel : myClass) {
            List<StuModel> studentModelList = classReqModel.studentModelList;
            for (StuModel srudentModel : studentModelList) {
                taskReport = new HomeworkTaskReport();
                taskReport.setTaskId(task.getId());
                taskReport.setTitle(task.getTitle());
                taskReport.setSubTitle(task.getSubTitle());
                taskReport.setStudentId(srudentModel.studentId);
                taskReport.setStudentNick(srudentModel.studentName);
                // 学生默认头像
                // String avaString =
                // StringUtils.defaultIfBlank(srudentModel.avatar, "默认头像链接");
                taskReport.setAvatar(srudentModel.avatar);
                taskReport.setSchoolId(schoolId);
                taskReport.setClassId(classReqModel.classId);
                taskReport.setClassName(classReqModel.classNick);
                taskReport.setLectureId(classReqModel.packId);
                taskReport.setGrade(classReqModel.grade);
                taskReport.setAnnual(annual);
                taskReport.setStage(stage);
                taskReport.setSubject(subject);
                taskReport.setSubjectName(subjectName);
                taskReport.setPredictDate(task.getPredictDate());
                taskReport.setPublishAnswer(task.getPublishAnswer());
                taskReport.setTaskType(task.getTaskType());
                taskReport.setPublishDate(task.getPublishDate());
                taskReport.setSource(1);// 来源, 备授课
                taskReport.setLectureType(0);// 备授课类型,文档只能为 "预习作业"
                taskReportList.add(taskReport);
            }
        }
        taskReportRepository.save(taskReportList);

    }

    /**
     * 发布试题作业
     * 
     * @param lectureType
     *            0: 预习作业 1: 复习作业
     * @param yxyLecturePrePack
     * @param requesRes
     * @param beginDate
     * @param doneDate
     * @param myClass
     * @param quesGoupName
     * @param schoolId
     * @param schoolName
     * @param userId
     * @param userNick
     * @throws ParseException
     */
    private void sendQuesHomeWork(YxyLectureRes lres, Integer lectureType, YxyLecturePrePack yxyLecturePrePack,
            String beginDate, String doneDate, List<MyClass> myClass, String quesGoupName, String schoolId,
            String schoolName, String userId, String userNick, List<String> parentsIdnew) {
        LOGGER.info("开始发布作业");
        Long start = System.currentTimeMillis();

        // 开始时间
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS Z");

        Date startDate = null;
        Date endDate = null;
        try {
            startDate = sdf.parse(beginDate.replace("Z", " UTC"));
            endDate = sdf.parse(doneDate.replace("Z", " UTC"));
            Assert.isTrue(startDate.getTime() < endDate.getTime(), "截止时间不能小于开始时间");
        } catch (ParseException e) {
            e.printStackTrace();
        }

        //

        HomeworkTask task = new HomeworkTask();
        List<String> classIdList = new ArrayList<String>();
        for (MyClass classReqModel : myClass) {
            String classId = classReqModel.classId;
            classIdList.add(classId);
        }
        // 学段, 学科,学科名称
        String stage = yxyLecturePrePack.getPhaseId();
        String subject = yxyLecturePrePack.getSubjectId();
        String subjectName = yxyLecturePrePack.getSubjectName();
        Map<String, List<Knows>> quesKnowMap = lres.getQuesKnows();
        List<Integer> knowIds = new ArrayList<Integer>();
        List<Knows> knowsName = new ArrayList<Knows>();
        List<String> knowsNameList = new ArrayList<String>();
        if (null != quesKnowMap) {
            quesKnowMap.values().stream().distinct();
            for (String key : quesKnowMap.keySet()) {
                knowsName = quesKnowMap.get(key);
            }
        }
        for (Knows knows : knowsName) {
            if (knows.know_id != null) {
                knowIds.add(Integer.valueOf(knows.know_id));
                knowsNameList.add(knows.know_name);
            }
        }
        task.setTitle(quesGoupName);
        task.setSubTitle(quesGoupName);
        task.setSchoolId(schoolId);
        task.setPublishUserId(userId);
        task.setPublishUserNick(userNick);
        task.setStage(stage);
        task.setSubject(subject);
        task.setSubjectName(subjectName);
        task.setPublishAnswer(0);
        task.setSource(1);// 来源
        task.setLectureType(lectureType);// 备授课类型
        task.setPublishDate(startDate);
        // 极光推送
        LectureCrtPackAndHomeworkController.sendMessage(subjectName, schoolId, parentsIdnew, startDate);
        task.setClassIds(classIdList);
        task.setPredictDate(endDate);
        task.setKnowIds(knowIds);
        task.setKnowNames(knowsNameList);
        task.setTaskType("0");
        task.setIfNeedSumbit(true);
        task = taskRepository.save(task);

        // 存储班级作业
        List<HomeworkTaskClass> taskClassList = new ArrayList<HomeworkTaskClass>();
        HomeworkTaskClass taskClass = null;
        for (MyClass classReqModel : myClass) {
            taskClass = new HomeworkTaskClass();
            taskClass.setTitle(task.getTitle());
            taskClass.setSubTitle(task.getSubTitle());
            taskClass.setClassId(classReqModel.classId);
            taskClass.setClassName(classReqModel.classNick);
            taskClass.setNumOfStudent(classReqModel.studentNum);
            taskClass.setGrade(classReqModel.grade);
            taskClass.setTaskId(task.getId());
            taskClass.setSchoolId(schoolId);
            taskClass.setStage(task.getStage());
            taskClass.setSubject(task.getSubject());
            taskClass.setSubjectName(task.getSubjectName());
            taskClass.setPublishDate(task.getPublishDate());
            taskClass.setPredictDate(task.getPredictDate());
            taskClass.setPublishUserId(task.getPublishUserId());
            taskClass.setPublishUserNick(task.getPublishUserNick());
            taskClass.setTaskType(task.getTaskType());
            taskClass.setSource(1);// 来源, 备授课
            taskClass.setLectureType(lectureType);
            taskClass.setLectureId(classReqModel.packId);
            taskClassList.add(taskClass);
        }
        taskClassRepository.save(taskClassList);

        // 存储试题, 试题类作业
        HomeworkTaskQues taskQues = null;
        HomeWorkQuesUsed quesUsed = null;
        List<HomeworkTaskQues> taskQuesList = new ArrayList<HomeworkTaskQues>();
        List<HomeWorkQuesUsed> quesUsedList = new ArrayList<HomeWorkQuesUsed>();
        int i = 1;

        for (String quesId : lres.getQuesIds()) {
            quesUsed = quesUsedRepository.findByQuesId(quesId);
            if (quesUsed != null) {
                quesUsed.setUsedCount(quesUsed.getUsedCount() + 1);
            } else {
                quesUsed = new HomeWorkQuesUsed();
                quesUsed.setQuesId(quesId);
                quesUsed.setUsedCount(1l);
            }
            quesUsedList.add(quesUsed);
            // 查询试题
            ElasticYxyYxyQuesResource eQues = elasticService.findByEsQuesId(quesId);
            taskQues = new HomeworkTaskQues();
            taskQues.setTitle(task.getTitle());
            taskQues.setSubTitle(task.getSubTitle());
            taskQues.setTaskId(task.getId());
            taskQues.setPredictDate(task.getPredictDate());
            taskQues.setQuesId(quesId);
            taskQues.setTeacherId(userId);
            taskQues.setStage(task.getStage());
            taskQues.setSubject(task.getSubject());
            taskQues.setOrder(i++);
            taskQues.setLectureType(lectureType);
            taskQues.setIfNeedSumbit(true);
            // 需要设置,设置试题的知识点 TODO
            // 题的知识点
            taskQues.setKnowId(knowIds);// 知识点id
            // 题的知识点名称
            List<YxyQuesKnow> quesKnows = qKnowRepository.findByIdIn(knowIds);
            List<String> knowTextsList = new ArrayList<String>();
            quesKnows.forEach(quesKnow -> {
                knowTextsList.add(quesKnow.getName());
            });
            taskQues.setKnowName(knowTextsList);
            taskQues.setDifficultyLevel(Integer.parseInt(eQues.getDifficultyLevel()));// 难度级别
            taskQues.setDifficultyXs(eQues.getDifficultyXishu());// 难度系数
            taskQues.setTaskType(task.getTaskType());
            String questionType = eQues.getQuestionType();
            if (StringUtils.equals(questionType, "1")) {
                taskQues.setQuesType("0");
            } else if (StringUtils.equals(questionType, "8")) {
                taskQues.setQuesType("1");
            } else if (StringUtils.equals(questionType, "2")) {
                taskQues.setQuesType("3");
            } else {
                taskQues.setQuesType("4");
            }
            taskQuesList.add(taskQues);
        }
        quesUsedRepository.save(quesUsedList);
        taskQuesRepository.save(taskQuesList);

        // 设置每个学生的试题作业
        // 年度
        List<HomeworkTaskReport> taskReportList = new ArrayList<HomeworkTaskReport>();
        HomeworkTaskReport taskReport = null;

        LocalDate localDate = LocalDate.now();
        String annual = null;
        if (localDate.getMonthValue() < 9) {
            annual = (localDate.getYear() - 1) + "";
        } else {
            annual = localDate.getYear() + "";
        }
        for (MyClass classReqModel : myClass) {
            List<StuModel> studentModelList = classReqModel.studentModelList;
            for (StuModel srudentModel : studentModelList) {
                taskReport = new HomeworkTaskReport();
                taskReport.setTaskId(task.getId());
                taskReport.setTitle(task.getTitle());
                taskReport.setSubTitle(task.getSubTitle());
                taskReport.setStudentId(srudentModel.studentId);
                taskReport.setStudentNick(srudentModel.studentName);
                // 学生默认头像
                // String avaString =
                // StringUtils.defaultIfBlank(srudentModel.avatar, "默认头像链接");
                taskReport.setAvatar(srudentModel.avatar);
                taskReport.setSchoolId(schoolId);
                taskReport.setClassId(classReqModel.classId);
                taskReport.setClassName(classReqModel.classNick);
                taskReport.setGrade(classReqModel.grade);
                taskReport.setAnnual(annual);
                taskReport.setStage(stage);
                taskReport.setSubject(subject);
                taskReport.setSubjectName(subjectName);
                taskReport.setPredictDate(task.getPredictDate());
                taskReport.setPublishAnswer(task.getPublishAnswer());
                taskReport.setTaskType(task.getTaskType());
                taskReport.setPublishDate(task.getPublishDate());
                taskReport.setSource(1);// 来源, 备授课
                taskReport.setLectureType(lectureType);// 备授课类型,文档只能为 "预习作业"
                taskReportList.add(taskReport);
            }
        }
        taskReportRepository.save(taskReportList);
        LOGGER.info("发布完成共用时:" + ((System.currentTimeMillis() - start) / 1000) + "s");

    }

    // 获得当天24点时间
    public static Date getTimesnight() {
        Calendar cal = Calendar.getInstance();
        cal.set(Calendar.HOUR_OF_DAY, 23);
        cal.set(Calendar.SECOND, 59);
        cal.set(Calendar.MINUTE, 59);
        cal.set(Calendar.MILLISECOND, 0);
        return cal.getTime();
    }

    // 获得本周日24点时间
    public static Date getTimesWeeknight() {
        Calendar cal = Calendar.getInstance();
        cal.setTime(getTimesWeekmorning());
        cal.add(Calendar.DAY_OF_WEEK, 6);
        return cal.getTime();
    }

    // 获得本周一0点时间
    public static Date getTimesWeekmorning() {
        Calendar cal = Calendar.getInstance();
        cal.set(cal.get(Calendar.YEAR), cal.get(Calendar.MONDAY), cal.get(Calendar.DAY_OF_MONTH), 23, 59, 59);
        cal.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY);
        return cal.getTime();
    }

    // 获得明天24点时间
    public static Date getTimesNextnight() {
        Calendar cal = Calendar.getInstance();
        cal.set(Calendar.HOUR_OF_DAY, 47);
        cal.set(Calendar.SECOND, 59);
        cal.set(Calendar.MINUTE, 59);
        cal.set(Calendar.MILLISECOND, 0);
        return cal.getTime();
    }

    /**
     * 转化题的请求信息为map
     */
    // private Map<String, List<Integer>> convertQuesToMap(List<QuesModel>
    // quesIdList) {
    // Map<String, List<Integer>> quesMap = new HashMap<String,
    // List<Integer>>();
    // quesIdList.forEach(ques -> {
    // quesMap.put(ques.quesId, ques.know);
    // });
    // return quesMap;
    // }

}
